package com.haitaoit.chengquan.module.home.adapter.parts;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BackCall;
import com.haitaoit.chengquan.module.home.model.MaintenanceModel;
import com.haitaoit.chengquan.view.CircleImageView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/10/24.
 */
public class MaintenanceAdapter extends BaseAdapter {
    private Context context;
    private BackCall backCall;
    private List<MaintenanceModel> list;

    public void setBackCall(BackCall backCall) {
        this.backCall = backCall;
    }

    public MaintenanceAdapter(Context context) {
        this.context = context;
    }

    public List<MaintenanceModel> getList() {
        return list;
    }

    public void setList(List<MaintenanceModel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.maintenance_item, null);
            holder = new ViewHolder();
            ViewUtils.inject(holder, convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        ImageLoader.getInstance().displayImage(list.get(position).getHead_portrait(), holder.man_img);
        holder.real_name.setText(list.get(position).getReal_name());
        holder.service_scope.setText("服务范围：" + list.get(position).getService_scope());
        holder.address.setText("所在地址：" + list.get(position).getAddress());
        holder.volume_count.setText("成交量：" + list.get(position).getVolume_count() + "家");
        return convertView;
    }

    class ViewHolder {
        @ViewInject(R.id.man_img)
        CircleImageView man_img;
        @ViewInject(R.id.real_name)
        TextView real_name;
        @ViewInject(R.id.service_scope)
        TextView service_scope;
        @ViewInject(R.id.address)
        TextView address;
        @ViewInject(R.id.volume_count)
        TextView volume_count;
    }
}
